package com.qing.common_result.config;

import com.qing.common_result.result.ResponseResultInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;


@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

	@Autowired
	private ResponseResultInterceptor responseResultInterceptor;


	public void addInterceptors(InterceptorRegistry registry) {
		//统一返回值拦截
		registry.addInterceptor(responseResultInterceptor).addPathPatterns("/**");
	}

	@Override
	public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
//		# com.chinaunicom.aurveyapp.app.result.HttpResult cannot be cast to java.lang.String
		converters.add(0, new MappingJackson2HttpMessageConverter());
	}

}
